<?php

require_once('../../includes/classes/core.php');
$action 	= $_REQUEST['act'];
$error		= '';
$data		= '';

switch ($action) {
	case 'get_list' :
		$count = 		$_REQUEST['count'];
		$hidden = 		$_REQUEST['hidden'];
		$start		= $_REQUEST['start'];
		$end		= $_REQUEST['end'];
	  	$rResult = mysql_query("SELECT DATE_FORMAT(asterisk_outgoing.call_datetime,'%d/%m/%y %H:%i:%s'),
								DATE_FORMAT(asterisk_outgoing.call_datetime,'%d/%m/%y %H:%i:%s'),
	  										asterisk_outgoing.extension,
											asterisk_outgoing.phone,
								TIME_FORMAT(SEC_TO_TIME(asterisk_outgoing.duration ),'%i:%s') as `time`,
						       	CONCAT('<p onclick=play(', '\'', asterisk_outgoing.file_name, '\'',  ')>მოსმენა</p>', '<a download=\"image.jpg\" href=\"http://91.233.15.136:8181/', asterisk_outgoing.file_name, '\">ჩამოტვირთვა</a>')
								FROM   asterisk_outgoing
								WHERE    DATE(asterisk_outgoing.call_datetime)  BETWEEN  date('$start')  And date('$end')
	  							AND asterisk_outgoing.extension NOT IN (501,502,503) and LENGTH(extension)=3");
	  
		$data = array(
				"aaData"	=> array()
		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				/* General output */
				$row[] = $aRow[$i];
			}
			$data['aaData'][] = $row;
		}

		break;
		
	default:
		$error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);

?>